 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.subway.rca.entity.ViewCkDataauditJiehangcash;
import com.zdkj.subway.rca.service.ViewCkDataauditJiehangcashService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 解行金额与车站现金缴款单据复核
 *
 * @author stw
 * @date 2020-11-01 11:06:31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/viewckdataauditjiehangcash" )
@Api(value = "viewckdataauditjiehangcash", tags = "报表调账-收入报表数据关联性复核-解行金额与车站现金缴款单据复核管理")
public class ViewCkDataauditJiehangcashController {

    private final ViewCkDataauditJiehangcashService viewCkDataauditJiehangcashService;
    /**
     * 报表调账-收入报表数据关联复核-解行金额与车站现金缴款单据复核-生成数据
     * @param startDate
     * @param endDate
     * @return R
     */
    @ApiOperation(value = "生成数据", notes = "生成数据")
    @SysLog("报表调账-收入报表数据关联复核-解行金额与车站现金缴款单据复核-生成数据" )
    @GetMapping({"/generate"})
    @PreAuthorize("@pms.hasPermission('sw_ck_dataaudit_jiehangcash_generate')" )
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
            }
    )
    public R generate(String startDate, String endDate) {
        try {
            if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
                return R.failed("开始日期和结束日期必选");
            }

            boolean flag = viewCkDataauditJiehangcashService.generate(startDate,endDate);

            return R.ok(flag);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed();
        }

    }

    /**
     * 分页查询
     * @param page 分页对象
     * @param startDate
     * @param endDate
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getViewCkDataauditJiehangcashPage(Page page, String startDate, String endDate) {
        ViewCkDataauditJiehangcash viewCkDataauditJiehangcash = new ViewCkDataauditJiehangcash();
        return R.ok(viewCkDataauditJiehangcashService.page(page, Wrappers.query(viewCkDataauditJiehangcash).lambda()
                .ge(StringUtils.isNotEmpty(startDate), ViewCkDataauditJiehangcash::getTradeDate, startDate)
                .le( StringUtils.isNotEmpty(endDate),ViewCkDataauditJiehangcash::getTradeDate, endDate)
                .orderByDesc(ViewCkDataauditJiehangcash::getTradeDate)));
    }

    /**
     * 导出
     * @param startDate
     * @param endDate
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "导出", notes = "导出")
    @GetMapping({"/exportGroupDate"})
    @SysLog("解行金额与车站现金缴款单据复核导出")
    @PreAuthorize("@pms.hasPermission('view_ck_dataaudit_jiehangcash_export')")
    public void exportExcel(String startDate, String endDate, HttpServletResponse response) {
        viewCkDataauditJiehangcashService.exportExcel(startDate,endDate,response);
    }
}
